package com.seele.tigerwallet.ui.activtiy;

import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.seele.tigerwallet.R;
import com.seele.tigerwallet.model.UserInfo;
import com.seele.tigerwallet.ui.base.TitleBaseActivity;
import com.seele.tigerwallet.ui.base.ToolbarBaseActivity;
import com.seele.tigerwallet.ui.event.ExchangeEvent;
import com.seele.tigerwallet.ui.utils.SPUtils;
import com.seele.tigerwallet.ui.views.LinearRelativeLayout;

import org.greenrobot.eventbus.EventBus;

public class TokenCompanySelectActivity extends ToolbarBaseActivity implements View.OnClickListener {


    private RelativeLayout mCNYRv;

    private RelativeLayout mUSDRv;

    private ImageView mCNYImg;

    private ImageView mUSDImg;



    @Override
    public int getContainerViewId() {
        return R.layout.activity_token_company_select;
    }

    @Override
    protected void initView() {
        setTitle(R.string.token_company);
        mCNYRv = $f(R.id.cny_rv);
        mUSDRv = $f(R.id.usd_rv);
        mCNYImg = $f(R.id.cny_img);
        mUSDImg = $f(R.id.usd_img);
        mCNYRv.setOnClickListener(this);
        mUSDRv.setOnClickListener(this);
        resetView();
        if (UserInfo.get().company == 0) {
            mUSDImg.setVisibility(View.VISIBLE);
        } else if (UserInfo.get().company == 1) {
            mCNYImg.setVisibility(View.VISIBLE);
        }

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.cny_rv:
                resetView();
                mCNYImg.setVisibility(View.VISIBLE);
                UserInfo.get().company = 1;
                SPUtils.saveUserInfo(UserInfo.get());
                break;
            case R.id.usd_rv:
                resetView();
                mUSDImg.setVisibility(View.VISIBLE);
                UserInfo.get().company = 0;
                SPUtils.saveUserInfo(UserInfo.get());
                break;
        }

    }

    private void resetView() {
        mCNYImg.setVisibility(View.GONE);
        mUSDImg.setVisibility(View.GONE);
    }

    @Override
    protected void onDestroy() {
        EventBus.getDefault().post(new ExchangeEvent());
        super.onDestroy();
    }
}
